<?php
/**
 * Created by PhpStorm.
 * User: ivi
 * Date: 2019/2/19
 * Time: 20:45
 */

namespace App\Http\Requests;


use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Validator;

class BaseFormRequest extends FormRequest
{
    /**
     * Get the validator instance for the request.
     *
     * @return \Illuminate\Validation\Validator
     */
    protected function getValidatorInstance()
    {
        $instance = parent::getValidatorInstance();
        $instance->after(function (Validator $validator) {
            if (!$validator->errors()->count()) {
                $result = $this->after();
                if ($result) {
                    $validator->errors()->add('field', $result);
                    return ['xx'];
                }
            }
        });
        return $instance;
    }

    protected function after()
    {
        return false;
    }

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [];
    }


    public function messages()
    {
        return [];
    }
}
